package com.buddies.lottery.base;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.buddies.lottery.R;

import java.util.ArrayList;

public class PagerAdapter extends FragmentPagerAdapter {

    private final Context mContext;
    private final ArrayList<String> mTabTexts;
    private final ArrayList<Fragment> mFragments;

    public PagerAdapter(Context context, FragmentManager fm, ArrayList<String> mTabTexts, ArrayList<Fragment> mFragments) {
        super(fm);
        this.mContext = context;
        this.mTabTexts = mTabTexts;
        this.mFragments = mFragments;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTabTexts.get(position);
    }

    @Override
    public Fragment getItem(int position) {
        return position < mFragments.size() ? mFragments.get(position) : new Fragment();
    }

    @Override
    public int getCount() {
        return mTabTexts.size();
    }

    public View getTabView(int position) {
        View v = LayoutInflater.from(mContext).inflate(R.layout.item_pager, null);
        TextView tv = (TextView) v.findViewById(R.id.tv);
        v.findViewById(R.id.iv).setVisibility(getCount() > 1 ? View.VISIBLE : View.GONE);
        tv.setText(mTabTexts.get(position));
        return v;
    }
}